home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / internet / sweeper / samples / olecon~1 / include / stdenum.h < prev    next >
Text File  |  1995-11-25  |  3KB  |  77 lines

  1. //=--------------------------------------------------------------------------=
  2. // StandardEnum.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright  1995  Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // object definition for a generic enumerator object.
  13. //
  14. #ifndef _STANDARDENUM_H_
  15.  
  16. #include "Unknown.H"
  17.  
  18. // to support a generic Enumerator object, we'll just define this
  19. // interface.  it can be safely cast to any other enumerator, since all
  20. // they differ in is their pointer type in Next().
  21. //
  22. class IEnumGeneric: public IUnknown {
  23.  
  24.   public:
  25.     virtual HRESULT __stdcall Next(ULONG celt, LPVOID rgelt, ULONG *pceltFetched) = 0;
  26.     virtual HRESULT __stdcall Skip(ULONG celt) = 0;
  27.     virtual HRESULT __stdcall Reset(void) = 0;
  28.     virtual HRESULT __stdcall Clone(IEnumGeneric **ppenum) = 0;
  29. };
  30.  
  31. //=--------------------------------------------------------------------------=
  32. // StandardEnum
  33. //=--------------------------------------------------------------------------=
  34. // a generic enumerator object.  given a pointer to generic data, some
  35. // information about the elements, and a function to copy the elements,
  36. // we can implement a generic enumerator.
  37. //
  38. // NOTE: this class assumes that rgElements is HeapAlloc'd, and will free it
  39. //       in it's destructor [although it IS valid for this to be NULL if there
  40. //       are no elements to enumerate over.]
  41. //
  42. class CStandardEnum: public CUnknownObject, public IEnumGeneric {
  43.  
  44. public:
  45.     // IUnknown methods
  46.     //
  47.     DECLARE_STANDARD_UNKNOWN();
  48.  
  49.     // IEnumVariant methods
  50.     //
  51.     STDMETHOD(Next)(unsigned long celt, void * rgvar, unsigned long * pceltFetched); 
  52.     STDMETHOD(Skip)(unsigned long celt); 
  53.     STDMETHOD(Reset)(); 
  54.     STDMETHOD(Clone)(IEnumGeneric **ppEnumOut); 
  55.  
  56.     CStandardEnum(REFIID riid, int cElement, int cbElement, void *rgElements,
  57.                  void (WINAPI * pfnCopyElement)(void *, const void *, DWORD));
  58.     ~CStandardEnum();
  59.  
  60. private:
  61.     virtual HRESULT InternalQueryInterface(REFIID riid, void **ppvObjOut);
  62.  
  63.     IID m_iid;                        // type of enumerator that we are
  64.     int m_cElements;                  // Total number of elements
  65.     int m_cbElementSize;              // Size of each element
  66.     int m_iCurrent;                   // Current position: 0 = front, m_cElt = end
  67.     VOID * m_rgElements;              // Array of elements  
  68.     CStandardEnum *m_pEnumClonedFrom; // If we were cloned, from whom?
  69.     void  (WINAPI * m_pfnCopyElement)(void *, const void *, DWORD);
  70. };
  71.  
  72.  
  73.  
  74. #define _STANDARDENUM_H_
  75. #endif // _STANDARDENUM_H_
  76.  
  77.